package com.zhj.leetcode;

/**
 * 力扣162 寻找峰值
 * @author zhj
 */
public class Test162 {
    public static void main(String[] args) {
        int[] nums = {1, 6, 1, 3, 4, 2};
        int result = findPeak(nums);
        System.out.println(result);
    }

    private static int findPeak(int[] nums) {
        if (nums == null || nums.length == 0) {
            return -1;
        }
        int l = 0;
        int r = nums.length-1;
        int mid = -1;
        while (l < r) {
            mid = l + (r - l) / 2;
            if (nums[mid] > nums[mid+1]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
}
